<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>47-DOM编程 | 小黑博客</title><meta name="keywords" content="JavaScript,JavaScript高级程序设计第四版"><meta name="author" content="BluesYoung-web"><meta name="copyright" content="BluesYoung-web"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="动态脚本 &lt;script&gt; 元素用于向网页中插入 JavaScript 代码 可以是 src 属性包含的外部文件 也可以是作为该元素内容的源代码 动态脚本就是在页面加载之后使用脚本额外加载的代码  1234567891011function loadScriptString(code)&amp;#123;   var script &#x3D; document.createElement(&quot;">
<meta property="og:type" content="article">
<meta property="og:title" content="47-DOM编程">
<meta property="og:url" content="https://bluesyoung-web.gitee.io/blog/2021-01-21-47-DOM%E7%BC%96%E7%A8%8B.html">
<meta property="og:site_name" content="小黑博客">
<meta property="og:description" content="动态脚本 &lt;script&gt; 元素用于向网页中插入 JavaScript 代码 可以是 src 属性包含的外部文件 也可以是作为该元素内容的源代码 动态脚本就是在页面加载之后使用脚本额外加载的代码  1234567891011function loadScriptString(code)&amp;#123;   var script &#x3D; document.createElement(&quot;">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://bluesyoung-web.gitee.io/blog/img/hbs.png">
<meta property="article:published_time" content="2021-01-21T06:03:36.000Z">
<meta property="article:modified_time" content="2021-08-29T11:36:10.269Z">
<meta property="article:author" content="BluesYoung-web">
<meta property="article:tag" content="JavaScript">
<meta property="article:tag" content="JavaScript高级程序设计第四版">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://bluesyoung-web.gitee.io/blog/img/hbs.png"><link rel="shortcut icon" href="/blog/img/favicon.png"><link rel="canonical" href="https://bluesyoung-web.gitee.io/blog/2021-01-21-47-DOM%E7%BC%96%E7%A8%8B"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: BluesYoung-web","link":"链接: ","source":"来源: 小黑博客","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"top-right"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '47-DOM编程',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2021-08-29 19:36:10'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/blog/css/background.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/HexoStaticFile@latest/Hexo/css/custom.min.css"></link><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/blog/img/lufei_siwangningshi.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">153</div></a></div><div class="data-item"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">54</div></a></div><div class="data-item"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">48</div></a></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/blog/img/hbs.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">小黑博客</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">47-DOM编程</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-01-21T06:03:36.000Z" title="发表于 2021-01-21 14:03:36">2021-01-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-08-29T11:36:10.269Z" title="更新于 2021-08-29 19:36:10">2021-08-29</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">学习笔记</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/JavaScript%E9%AB%98%E7%BA%A7%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1/">JavaScript高级程序设计</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/JavaScript%E9%AB%98%E7%BA%A7%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1/%E7%AC%AC14%E7%AB%A0%E2%80%94%E2%80%94DOM/">第14章——DOM</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>9分钟</span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="动态脚本"><a href="#动态脚本" class="headerlink" title="动态脚本"></a>动态脚本</h2><ul>
<li><code>&lt;script&gt;</code> 元素用于向网页中插入 <code>JavaScript</code> 代码</li>
<li>可以是 <code>src</code> 属性包含的外部文件</li>
<li>也可以是作为该元素内容的源代码</li>
<li>动态脚本就是在页面加载之后使用脚本<strong>额外加载</strong>的代码</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">loadScriptString</span>(<span class="params">code</span>)</span>&#123;</span><br><span class="line">   <span class="keyword">var</span> script = <span class="built_in">document</span>.createElement(<span class="string">&quot;script&quot;</span>);</span><br><span class="line">   script.type = <span class="string">&quot;text/javascript&quot;</span>;</span><br><span class="line">   <span class="keyword">try</span> &#123;</span><br><span class="line">   		script.appendChild(<span class="built_in">document</span>.createTextNode(code));</span><br><span class="line">   &#125; <span class="keyword">catch</span> (ex)&#123;</span><br><span class="line">   		script.text = code;</span><br><span class="line">   &#125;</span><br><span class="line">   <span class="built_in">document</span>.body.appendChild(script);</span><br><span class="line">&#125; </span><br><span class="line">loadScriptString(<span class="string">&quot;function sayHi()&#123;alert(&#x27;hi&#x27;);&#125;&quot;</span>); </span><br></pre></td></tr></table></figure>

<h2 id="动态样式"><a href="#动态样式" class="headerlink" title="动态样式"></a>动态样式</h2><ul>
<li><code>&lt;link&gt;</code> 标签动态引入</li>
<li><code>&lt;style&gt;</code> 标签动态写入</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">loadStyles</span>(<span class="params">url</span>)</span>&#123;</span><br><span class="line">   <span class="keyword">let</span> link = <span class="built_in">document</span>.createElement(<span class="string">&quot;link&quot;</span>);</span><br><span class="line">   link.rel = <span class="string">&quot;stylesheet&quot;</span>;</span><br><span class="line">   link.type = <span class="string">&quot;text/css&quot;</span>;</span><br><span class="line">   link.href = url;</span><br><span class="line">   <span class="keyword">let</span> head = <span class="built_in">document</span>.getElementsByTagName(<span class="string">&quot;head&quot;</span>)[<span class="number">0</span>];</span><br><span class="line">   head.appendChild(link);</span><br><span class="line">&#125; </span><br><span class="line">loadStyles(<span class="string">&quot;styles.css&quot;</span>); </span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">loadStyleString</span>(<span class="params">css</span>)</span>&#123;</span><br><span class="line">   <span class="keyword">let</span> style = <span class="built_in">document</span>.createElement(<span class="string">&quot;style&quot;</span>);</span><br><span class="line">   style.type = <span class="string">&quot;text/css&quot;</span>;</span><br><span class="line">   <span class="keyword">try</span>&#123;</span><br><span class="line">   		style.appendChild(<span class="built_in">document</span>.createTextNode(css));</span><br><span class="line">   &#125; <span class="keyword">catch</span> (ex)&#123;</span><br><span class="line">   		style.styleSheet.cssText = css;</span><br><span class="line">   &#125;</span><br><span class="line">   <span class="keyword">let</span> head = <span class="built_in">document</span>.getElementsByTagName(<span class="string">&quot;head&quot;</span>)[<span class="number">0</span>];</span><br><span class="line">   head.appendChild(style);</span><br><span class="line">&#125; </span><br><span class="line">loadStyleString(<span class="string">&quot;body&#123;background-color:red&#125;&quot;</span>); </span><br></pre></td></tr></table></figure>

<h2 id="动态表格"><a href="#动态表格" class="headerlink" title="动态表格"></a>动态表格</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 创建表格</span></span><br><span class="line"><span class="keyword">let</span> table = <span class="built_in">document</span>.createElement(<span class="string">&quot;table&quot;</span>);</span><br><span class="line">table.border = <span class="number">1</span>;</span><br><span class="line">table.width = <span class="string">&quot;100%&quot;</span>;</span><br><span class="line"><span class="comment">// 创建表体</span></span><br><span class="line"><span class="keyword">let</span> tbody = <span class="built_in">document</span>.createElement(<span class="string">&quot;tbody&quot;</span>);</span><br><span class="line">table.appendChild(tbody);</span><br><span class="line"><span class="comment">// 创建第一行</span></span><br><span class="line"><span class="keyword">let</span> row1 = <span class="built_in">document</span>.createElement(<span class="string">&quot;tr&quot;</span>);</span><br><span class="line">tbody.appendChild(row1);</span><br><span class="line"><span class="keyword">let</span> cell1_1 = <span class="built_in">document</span>.createElement(<span class="string">&quot;td&quot;</span>);</span><br><span class="line">cell1_1.appendChild(<span class="built_in">document</span>.createTextNode(<span class="string">&quot;Cell 1,1&quot;</span>));</span><br><span class="line">row1.appendChild(cell1_1);</span><br><span class="line"><span class="keyword">let</span> cell2_1 = <span class="built_in">document</span>.createElement(<span class="string">&quot;td&quot;</span>);</span><br><span class="line">cell2_1.appendChild(<span class="built_in">document</span>.createTextNode(<span class="string">&quot;Cell 2,1&quot;</span>));</span><br><span class="line">row1.appendChild(cell2_1);</span><br><span class="line"><span class="comment">// 创建第二行</span></span><br><span class="line"><span class="keyword">let</span> row2 = <span class="built_in">document</span>.createElement(<span class="string">&quot;tr&quot;</span>);</span><br><span class="line">tbody.appendChild(row2);</span><br><span class="line"><span class="keyword">let</span> cell1_2 = <span class="built_in">document</span>.createElement(<span class="string">&quot;td&quot;</span>);</span><br><span class="line">cell1_2.appendChild(<span class="built_in">document</span>.createTextNode(<span class="string">&quot;Cell 1,2&quot;</span>));</span><br><span class="line">row2.appendChild(cell1_2);</span><br><span class="line"><span class="keyword">let</span> cell2_2= <span class="built_in">document</span>.createElement(<span class="string">&quot;td&quot;</span>);</span><br><span class="line">cell2_2.appendChild(<span class="built_in">document</span>.createTextNode(<span class="string">&quot;Cell 2,2&quot;</span>));</span><br><span class="line">row2.appendChild(cell2_2);</span><br><span class="line"><span class="comment">// 把表格添加到文档主体</span></span><br><span class="line"><span class="built_in">document</span>.body.appendChild(table); </span><br></pre></td></tr></table></figure>

<h3 id="lt-table-gt-元素的属性及方法"><a href="#lt-table-gt-元素的属性及方法" class="headerlink" title="&lt;table&gt; 元素的属性及方法"></a><code>&lt;table&gt;</code> 元素的属性及方法</h3><table>
<thead>
<tr>
<th><code>name</code></th>
<th><code>des</code></th>
</tr>
</thead>
<tbody><tr>
<td><code>caption</code></td>
<td>指向 <code>&lt;caption&gt;</code> 元素的指针(如果存在)</td>
</tr>
<tr>
<td><code>tBodies</code></td>
<td>包含 <code>&lt;tbody&gt;</code> 元素的集合</td>
</tr>
<tr>
<td><code>tFoot</code></td>
<td>指向 <code>&lt;tfoot&gt;</code> 元素</td>
</tr>
<tr>
<td><code>tHead</code></td>
<td>指向 <code>&lt;thead&gt;</code> 元素</td>
</tr>
<tr>
<td><code>rows</code></td>
<td>包含表示所有行的集合</td>
</tr>
<tr>
<td><code>createTHead()</code></td>
<td>创建 <code>&lt;thead&gt;</code> 元素，放到表格中，返回引用</td>
</tr>
<tr>
<td><code>createTFoot()</code></td>
<td>创建 <code>&lt;tfoot&gt;</code> 元素，放到表格中，返回引用</td>
</tr>
<tr>
<td><code>createCaption()</code></td>
<td>创建 <code>&lt;caption&gt;</code> 元素，放到表格中，返回引用</td>
</tr>
<tr>
<td><code>deleteTHead()</code></td>
<td>删除 <code>&lt;thead&gt;</code> 元素</td>
</tr>
<tr>
<td><code>deleteTFoot()</code></td>
<td>删除 <code>&lt;tfoot&gt;</code> 元素</td>
</tr>
<tr>
<td><code>deleteCaption()</code></td>
<td>删除 <code>&lt;caption&gt;</code> 元素</td>
</tr>
<tr>
<td><code>deleteRow(index)</code></td>
<td>删除指定位置的行</td>
</tr>
<tr>
<td><code>insertRow(index)</code></td>
<td>在指定位置插入一行</td>
</tr>
</tbody></table>
<h3 id="lt-tbody-gt-元素的属性及方法"><a href="#lt-tbody-gt-元素的属性及方法" class="headerlink" title="&lt;tbody&gt; 元素的属性及方法"></a><code>&lt;tbody&gt;</code> 元素的属性及方法</h3><table>
<thead>
<tr>
<th><code>name</code></th>
<th><code>des</code></th>
</tr>
</thead>
<tbody><tr>
<td><code>rows</code></td>
<td>包含 <code>&lt;tbody&gt;</code> 元素中所有行的集合</td>
</tr>
<tr>
<td><code>deleteRow(index)</code></td>
<td>删除指定行</td>
</tr>
<tr>
<td><code>insertRow(index)</code></td>
<td>在指定位置插入一行，返回该行的引用</td>
</tr>
</tbody></table>
<h3 id="lt-tr-gt-元素的属性及方法"><a href="#lt-tr-gt-元素的属性及方法" class="headerlink" title="&lt;tr&gt; 元素的属性及方法"></a><code>&lt;tr&gt;</code> 元素的属性及方法</h3><table>
<thead>
<tr>
<th><code>name</code></th>
<th><code>des</code></th>
</tr>
</thead>
<tbody><tr>
<td><code>cells</code></td>
<td>包含 <code>&lt;tr&gt;</code> 元素所有表元的集合</td>
</tr>
<tr>
<td><code>deleteCell(index)</code></td>
<td>删除指定位置的表元</td>
</tr>
<tr>
<td><code>insertCell(index)</code></td>
<td>在指定位置插入一个表元，返回该表元的引用</td>
</tr>
</tbody></table>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> table = <span class="built_in">document</span>.createElement(<span class="string">&quot;table&quot;</span>);</span><br><span class="line">table.border = <span class="number">1</span>;</span><br><span class="line">table.width = <span class="string">&quot;100%&quot;</span>;</span><br><span class="line"><span class="comment">// 创建表体</span></span><br><span class="line"><span class="keyword">let</span> tbody = <span class="built_in">document</span>.createElement(<span class="string">&quot;tbody&quot;</span>);</span><br><span class="line">table.appendChild(tbody);</span><br><span class="line"><span class="comment">// 创建第一行</span></span><br><span class="line">tbody.insertRow(<span class="number">0</span>);</span><br><span class="line">tbody.rows[<span class="number">0</span>].insertCell(<span class="number">0</span>);</span><br><span class="line">tbody.rows[<span class="number">0</span>].cells[<span class="number">0</span>].appendChild(<span class="built_in">document</span>.createTextNode(<span class="string">&quot;Cell 1,1&quot;</span>));</span><br><span class="line">tbody.rows[<span class="number">0</span>].insertCell(<span class="number">1</span>);</span><br><span class="line">tbody.rows[<span class="number">0</span>].cells[<span class="number">1</span>].appendChild(<span class="built_in">document</span>.createTextNode(<span class="string">&quot;Cell 2,1&quot;</span>));</span><br><span class="line"><span class="comment">// 创建第二行</span></span><br><span class="line">tbody.insertRow(<span class="number">1</span>);</span><br><span class="line">tbody.rows[<span class="number">1</span>].insertCell(<span class="number">0</span>);</span><br><span class="line">tbody.rows[<span class="number">1</span>].cells[<span class="number">0</span>].appendChild(<span class="built_in">document</span>.createTextNode(<span class="string">&quot;Cell 1,2&quot;</span>));</span><br><span class="line">tbody.rows[<span class="number">1</span>].insertCell(<span class="number">1</span>);</span><br><span class="line">tbody.rows[<span class="number">1</span>].cells[<span class="number">1</span>].appendChild(<span class="built_in">document</span>.createTextNode(<span class="string">&quot;Cell 2,2&quot;</span>));</span><br><span class="line"><span class="comment">// 把表格添加到文档主体</span></span><br><span class="line"><span class="built_in">document</span>.body.appendChild(table); </span><br></pre></td></tr></table></figure>

<h2 id="NodeList"><a href="#NodeList" class="headerlink" title="NodeList"></a><code>NodeList</code></h2><ul>
<li>基于 <code>DOM</code> 文档的实时查询</li>
<li>文档结构的变化会<strong>实时</strong>地在它们身上反映出来</li>
<li>任何时候要迭代 <code>NodeList</code>，最好再<strong>初始化一个变量</strong>保存当时查询时的长度，然后用循环变量与这个变量进行比较</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> divs = <span class="built_in">document</span>.getElementsByTagName(<span class="string">&quot;div&quot;</span>);</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>, len = divs.length; i &lt; len; ++i) &#123;</span><br><span class="line">   <span class="keyword">let</span> div = <span class="built_in">document</span>.createElement(<span class="string">&quot;div&quot;</span>);</span><br><span class="line">   <span class="built_in">document</span>.body.appendChild(div);</span><br><span class="line">&#125; </span><br></pre></td></tr></table></figure>

<h2 id="MutationObserver"><a href="#MutationObserver" class="headerlink" title="MutationObserver"></a><code>MutationObserver</code></h2><ul>
<li>可以在 <code>DOM </code> 被修改时异步执行回调</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> observer = <span class="keyword">new</span> MutationObserver(<span class="function">() =&gt;</span> <span class="built_in">console</span>.log(<span class="string">&#x27;&lt;body&gt; attributes changed&#x27;</span>));</span><br><span class="line">observer.observe(<span class="built_in">document</span>.body, &#123; <span class="attr">attributes</span>: <span class="literal">true</span> &#125;); </span><br><span class="line"><span class="built_in">document</span>.body.className = <span class="string">&#x27;foo&#x27;</span>;</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">&#x27;Changed body class&#x27;</span>);</span><br><span class="line"><span class="comment">// Changed body class</span></span><br><span class="line"><span class="comment">// &lt;body&gt; attributes changed </span></span><br></pre></td></tr></table></figure>

<h3 id="回调与-MutationRecord"><a href="#回调与-MutationRecord" class="headerlink" title="回调与 MutationRecord"></a>回调与 <code>MutationRecord</code></h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> observer = <span class="keyword">new</span> MutationObserver(<span class="function">(<span class="params">mutationRecords</span>) =&gt;</span> <span class="built_in">console</span>.log(mutationRecords));</span><br><span class="line">observer.observe(<span class="built_in">document</span>.body, &#123; <span class="attr">attributes</span>: <span class="literal">true</span> &#125;);</span><br><span class="line"><span class="built_in">document</span>.body.className = <span class="string">&#x27;foo&#x27;</span>;</span><br><span class="line"><span class="built_in">document</span>.body.className = <span class="string">&#x27;bar&#x27;</span>;</span><br><span class="line"><span class="built_in">document</span>.body.className = <span class="string">&#x27;baz&#x27;</span>; </span><br><span class="line"><span class="comment">// [MutationRecord, MutationRecord, MutationRecord] </span></span><br></pre></td></tr></table></figure>

<h3 id="实例属性"><a href="#实例属性" class="headerlink" title="实例属性"></a>实例属性</h3><ul>
<li><p><code>target</code> 被修改影响的目标节点</p>
</li>
<li><p><code>type</code> 字符串，表示变化类型</p>
</li>
<li><p><code>oldValue</code> 如果在 <code>MutationObserverInit </code>对象中启用（<code>attributeOldValue </code>或 <code>characterData </code> <code>OldValue </code>为 <code>true</code>），”<code>attributes</code>“或”<code>characterData</code>“的变化事件会设置这个属性为被替代的值 “<code>childList</code>“类型的变化始终将这个属性设置为 <code>null</code></p>
</li>
<li><p><code>attributeName</code> 对于”<code>attributes</code>“类型的变化，这里保存被修改属性的名字其他变化事件会将这个属性设置为 <code>null</code></p>
</li>
<li><p><code>attributeNamespace</code> 对于使用了命名空间的”<code>attributes</code>“类型的变化，这里保存被修改属性的名字其他变化事件会将这个属性设置为 <code>null</code></p>
</li>
<li><p><code>addedNodes</code> 对于”<code>childList</code>“类型的变化，返回包含变化中添加节点的 <code>NodeList </code>默认为空 <code>NodeList</code></p>
</li>
<li><p><code>removedNodes</code> 对于”<code>childList</code>“类型的变化，返回包含变化中删除节点的 <code>NodeList </code>默认为空 <code>NodeList</code></p>
</li>
<li><p><code>previousSibling</code> 对于”<code>childList</code>“类型的变化，返回变化节点的前一个同胞 <code>Node </code>默认为 <code>null</code></p>
</li>
<li><p><code>nextSibling</code> 对于”<code>childList</code>“类型的变化，返回变化节点的后一个同胞 <code>Node </code> 默认为 <code>null</code></p>
</li>
</ul>
<h3 id="提前结束观察"><a href="#提前结束观察" class="headerlink" title="提前结束观察"></a>提前结束观察</h3><ul>
<li><code>observer.disconnect()</code></li>
</ul>
<h3 id="复用-MutationObserver"><a href="#复用-MutationObserver" class="headerlink" title="复用 MutationObserver"></a>复用 <code>MutationObserver</code></h3><ul>
<li>多次调用 <code>observe()</code> 方法，可以复用一个 <code>MutationObserver </code>对象观察多个不同的目标节点</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> observer = <span class="keyword">new</span> MutationObserver(<span class="function">(<span class="params">mutationRecords</span>) =&gt;</span> <span class="built_in">console</span>.log(mutationRecords.map(<span class="function">(<span class="params">x</span>) =&gt;</span> x.target)));</span><br><span class="line"><span class="comment">// 向页面主体添加两个子节点</span></span><br><span class="line"><span class="keyword">let</span> childA = <span class="built_in">document</span>.createElement(<span class="string">&#x27;div&#x27;</span>),</span><br><span class="line"> childB = <span class="built_in">document</span>.createElement(<span class="string">&#x27;span&#x27;</span>);</span><br><span class="line"><span class="built_in">document</span>.body.appendChild(childA);</span><br><span class="line"><span class="built_in">document</span>.body.appendChild(childB);</span><br><span class="line"><span class="comment">// 观察两个子节点</span></span><br><span class="line">observer.observe(childA, &#123; <span class="attr">attributes</span>: <span class="literal">true</span> &#125;);</span><br><span class="line">observer.observe(childB, &#123; <span class="attr">attributes</span>: <span class="literal">true</span> &#125;); </span><br></pre></td></tr></table></figure>

<h3 id="重用-MutationObserver"><a href="#重用-MutationObserver" class="headerlink" title="重用 MutationObserver"></a>重用 <code>MutationObserver</code></h3><ul>
<li>调用 <code>disconnect()</code> <strong>并不会结束</strong> <code>MutationObserver </code>的生命</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> observer = <span class="keyword">new</span> MutationObserver(<span class="function">() =&gt;</span> <span class="built_in">console</span>.log(<span class="string">&#x27;&lt;body&gt; attributes changed&#x27;</span>));</span><br><span class="line">observer.observe(<span class="built_in">document</span>.body, &#123; <span class="attr">attributes</span>: <span class="literal">true</span> &#125;);</span><br><span class="line"><span class="comment">// 这行代码会触发变化事件</span></span><br><span class="line"><span class="built_in">document</span>.body.setAttribute(<span class="string">&#x27;foo&#x27;</span>, <span class="string">&#x27;bar&#x27;</span>);</span><br><span class="line"><span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">   observer.disconnect();</span><br><span class="line">   <span class="comment">// 这行代码不会触发变化事件</span></span><br><span class="line">   <span class="built_in">document</span>.body.setAttribute(<span class="string">&#x27;bar&#x27;</span>, <span class="string">&#x27;baz&#x27;</span>);</span><br><span class="line">&#125;, <span class="number">0</span>);</span><br><span class="line"><span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">   <span class="comment">// Reattach</span></span><br><span class="line">   observer.observe(<span class="built_in">document</span>.body, &#123; <span class="attr">attributes</span>: <span class="literal">true</span> &#125;);</span><br><span class="line">   <span class="comment">// 这行代码会触发变化事件</span></span><br><span class="line">   <span class="built_in">document</span>.body.setAttribute(<span class="string">&#x27;baz&#x27;</span>, <span class="string">&#x27;qux&#x27;</span>);</span><br><span class="line">&#125;, <span class="number">0</span>);</span><br><span class="line"><span class="comment">// &lt;body&gt; attributes changed</span></span><br><span class="line"><span class="comment">// &lt;body&gt; attributes changed </span></span><br></pre></td></tr></table></figure>

<h3 id="初始化对象与观察范围"><a href="#初始化对象与观察范围" class="headerlink" title="初始化对象与观察范围"></a>初始化对象与观察范围</h3><h4 id="初始化对象的属性"><a href="#初始化对象的属性" class="headerlink" title="初始化对象的属性"></a>初始化对象的属性</h4><table>
<thead>
<tr>
<th><code>name</code></th>
<th><code>des</code></th>
</tr>
</thead>
<tbody><tr>
<td><code>subtree</code></td>
<td>布尔值，表示除了目标节点，是否观察目标节点的子树（后代）<br />如果是 false，则只观察目标节点的变化<br />如果是 true，则观察目标节点及其整个子树 默认为 false</td>
</tr>
<tr>
<td><code>attributes</code></td>
<td>布尔值，表示是否观察目标节点的属性变化 默认为 false</td>
</tr>
<tr>
<td><code>attributeFilter</code></td>
<td>字符串数组，表示要观察哪些属性的变化<br />把这个值设置为 true 也会将 attributes 的值转换为 true<br />默认为观察所有属性</td>
</tr>
<tr>
<td><code>attributeOldValue</code></td>
<td>布尔值，表示 <code>MutationRecord </code>是否记录变化之前的属性值<br />把这个值设置为 true 也会将 attributes 的值转换为 true<br />默认为 false</td>
</tr>
<tr>
<td><code>characterData</code></td>
<td>布尔值，表示修改字符数据是否触发变化事件<br />默认为 false</td>
</tr>
<tr>
<td><code>characterDataOldValue</code></td>
<td>布尔值，表示 <code>MutationRecord </code>是否记录变化之前的字符数据<br />把这个值设置为 true 也会将 <code>characterData </code>的值转换为 true<br />默认为 false</td>
</tr>
<tr>
<td><code>childList</code></td>
<td>布尔值，表示修改目标节点的子节点是否触发变化事件<br />默认为 false</td>
</tr>
</tbody></table>
<blockquote>
<p>在调用 observe()时，<code>MutationObserverInit </code>对象中的 <code>attribute</code>、<code>characterData </code>和 <code>childList </code>属性必须至少有一项为 <code>true</code>（无论是直接设置这几个属性，还是通过设置 <code>attributeOldValue </code>等属性间接导致它们的值转换为 true）。否则会抛出错误，因为没 有任何变化事件可能触发回调</p>
</blockquote>
<h4 id="观察属性"><a href="#观察属性" class="headerlink" title="观察属性"></a>观察属性</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> observer = <span class="keyword">new</span> MutationObserver(<span class="function">(<span class="params">mutationRecords</span>) =&gt;</span> <span class="built_in">console</span>.log(mutationRecords));</span><br><span class="line">observer.observe(<span class="built_in">document</span>.body, &#123; <span class="attr">attributes</span>: <span class="literal">true</span> &#125;);</span><br><span class="line"><span class="comment">// 添加属性</span></span><br><span class="line"><span class="built_in">document</span>.body.setAttribute(<span class="string">&#x27;foo&#x27;</span>, <span class="string">&#x27;bar&#x27;</span>);</span><br><span class="line"><span class="comment">// 修改属性</span></span><br><span class="line"><span class="built_in">document</span>.body.setAttribute(<span class="string">&#x27;foo&#x27;</span>, <span class="string">&#x27;baz&#x27;</span>);</span><br><span class="line"><span class="comment">// 移除属性</span></span><br><span class="line"><span class="built_in">document</span>.body.removeAttribute(<span class="string">&#x27;foo&#x27;</span>);</span><br><span class="line"><span class="comment">// 以上变化都被记录下来了</span></span><br><span class="line"><span class="comment">// [MutationRecord, MutationRecord, MutationRecord] </span></span><br><span class="line"></span><br><span class="line">observer.observe(<span class="built_in">document</span>.body, &#123; <span class="attr">attributeFilter</span>: [<span class="string">&#x27;foo&#x27;</span>] &#125;);</span><br><span class="line"><span class="comment">// 添加白名单属性</span></span><br><span class="line"><span class="built_in">document</span>.body.setAttribute(<span class="string">&#x27;foo&#x27;</span>, <span class="string">&#x27;bar&#x27;</span>);</span><br><span class="line"><span class="comment">// 添加被排除的属性</span></span><br><span class="line"><span class="built_in">document</span>.body.setAttribute(<span class="string">&#x27;baz&#x27;</span>, <span class="string">&#x27;qux&#x27;</span>); </span><br><span class="line"><span class="comment">// 只有 foo 属性的变化被记录了</span></span><br><span class="line"><span class="comment">// [MutationRecord] </span></span><br></pre></td></tr></table></figure>

<h4 id="观察字符数据"><a href="#观察字符数据" class="headerlink" title="观察字符数据"></a>观察字符数据</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> observer = <span class="keyword">new</span> MutationObserver(<span class="function">(<span class="params">mutationRecords</span>) =&gt;</span> <span class="built_in">console</span>.log(mutationRecords));</span><br><span class="line"><span class="comment">// 创建要观察的文本节点</span></span><br><span class="line"><span class="built_in">document</span>.body.firstChild.textContent = <span class="string">&#x27;foo&#x27;</span>;</span><br><span class="line">observer.observe(<span class="built_in">document</span>.body.firstChild, &#123; <span class="attr">characterData</span>: <span class="literal">true</span> &#125;);</span><br><span class="line"><span class="comment">// 赋值为相同的字符串</span></span><br><span class="line"><span class="built_in">document</span>.body.firstChild.textContent = <span class="string">&#x27;foo&#x27;</span>;</span><br><span class="line"><span class="comment">// 赋值为新字符串</span></span><br><span class="line"><span class="built_in">document</span>.body.firstChild.textContent = <span class="string">&#x27;bar&#x27;</span>;</span><br><span class="line"><span class="comment">// 通过节点设置函数赋值</span></span><br><span class="line"><span class="built_in">document</span>.body.firstChild.textContent = <span class="string">&#x27;baz&#x27;</span>;</span><br><span class="line"><span class="comment">// 以上变化都被记录下来了</span></span><br><span class="line"><span class="comment">// [MutationRecord, MutationRecord, MutationRecord] </span></span><br></pre></td></tr></table></figure>

<h3 id="记录队列"><a href="#记录队列" class="headerlink" title="记录队列"></a>记录队列</h3><ul>
<li><p>每次 <code>MutationRecord </code> 被添加到 <code>MutationObserver </code> 的记录队列时，仅当之前没有已排期的微任务回调时（队列中微任务长度为 0），才会将观察者注册的回调（在初始化 <code>MutationObserver </code> 时传入）作为微任务调度到任务队列上</p>
</li>
<li><p>这样可以保证记录队列的内容不会被回调处理两次</p>
</li>
<li><p><code>observe.takeRecords()</code> 清空记录队列，取出并返回其中的所有 <code>MutationRecord </code> 实例</p>
</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">BluesYoung-web</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://bluesyoung-web.gitee.io/blog/2021-01-21-47-DOM%E7%BC%96%E7%A8%8B.html">https://bluesyoung-web.gitee.io/blog/2021-01-21-47-DOM%E7%BC%96%E7%A8%8B.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://BluesYoung-web.gitee.io/blog" target="_blank">小黑博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/JavaScript/">JavaScript</a><a class="post-meta__tags" href="/blog/tags/JavaScript%E9%AB%98%E7%BA%A7%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E7%AC%AC%E5%9B%9B%E7%89%88/">JavaScript高级程序设计第四版</a></div><div class="post_share"></div></div><div class="post-reward"><div class="reward-button button--animated"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/blog/img/wx.png" target="_blank"><img class="post-qr-code-img" src="/blog/img/wx.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/blog/img/zfb.jpg" target="_blank"><img class="post-qr-code-img" src="/blog/img/zfb.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/2020-12-28-01-历史回顾.html" title="01-历史回顾"><img class="cover" src="/blog/img/hbs.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-12-28</div><div class="title">01-历史回顾</div></div></a></div><div><a href="/blog/2020-12-28-03-script元素.html" title="03-script元素"><img class="cover" src="/blog/img/hbs.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-12-28</div><div class="title">03-script元素</div></div></a></div><div><a href="/blog/2020-12-28-02-实现.html" title="02-实现"><img class="cover" src="/blog/img/hbs.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-12-28</div><div class="title">02-实现</div></div></a></div><div><a href="/blog/2020-12-28-04-文档模式.html" title="04-文档模式"><img class="cover" src="/blog/img/hbs.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-12-28</div><div class="title">04-文档模式</div></div></a></div><div><a href="/blog/2020-12-28-05-语法.html" title="05-语法"><img class="cover" src="/blog/img/hbs.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-12-28</div><div class="title">05-语法</div></div></a></div><div><a href="/blog/2020-12-28-06-变量声明.html" title="06-变量声明"><img class="cover" src="/blog/img/hbs.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-12-28</div><div class="title">06-变量声明</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/blog/img/lufei_siwangningshi.jpg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">BluesYoung-web</div><div class="author-info__description">一枚不善言辞的技术宅</div></div><div class="card-info-data is-center"><div class="card-info-data-item"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">153</div></a></div><div class="card-info-data-item"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">54</div></a></div><div class="card-info-data-item"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">48</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/BluesYoung-web"><i class="fab fa-gitee"></i><span>点个小星星吧</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/BluesYoung-web" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:15171255945@163.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2021-08-24-%E7%A7%BB%E5%8A%A8%E7%AB%AF%E8%BD%AF%E9%94%AE%E7%9B%98%E5%AF%BC%E8%87%B4%E5%B8%83%E5%B1%80%E9%94%99%E4%B9%B1.html" title="移动端软键盘导致布局错乱"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="移动端软键盘导致布局错乱"/></a><div class="content"><a class="title" href="/blog/2021-08-24-%E7%A7%BB%E5%8A%A8%E7%AB%AF%E8%BD%AF%E9%94%AE%E7%9B%98%E5%AF%BC%E8%87%B4%E5%B8%83%E5%B1%80%E9%94%99%E4%B9%B1.html" title="移动端软键盘导致布局错乱">移动端软键盘导致布局错乱</a><time datetime="2021-08-24T10:01:20.000Z" title="发表于 2021-08-24 18:01:20">2021-08-24</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021-08-16-Linux%E5%AE%89%E8%A3%85you-get.html" title="Linux安装you-get"><img src="/blog/img/shumeipai_cover.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="Linux安装you-get"/></a><div class="content"><a class="title" href="/blog/2021-08-16-Linux%E5%AE%89%E8%A3%85you-get.html" title="Linux安装you-get">Linux安装you-get</a><time datetime="2021-08-16T08:07:31.000Z" title="发表于 2021-08-16 16:07:31">2021-08-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021-08-16-git%E5%88%A0%E9%99%A4%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%E7%9A%84%E6%8F%90%E4%BA%A4.html" title="git删除远程仓库的提交"><img src="/blog/img/skill.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="git删除远程仓库的提交"/></a><div class="content"><a class="title" href="/blog/2021-08-16-git%E5%88%A0%E9%99%A4%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%E7%9A%84%E6%8F%90%E4%BA%A4.html" title="git删除远程仓库的提交">git删除远程仓库的提交</a><time datetime="2021-08-16T07:52:02.000Z" title="发表于 2021-08-16 15:52:02">2021-08-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021-08-13-%E5%B0%86pad%E6%89%A9%E5%B1%95%E4%B8%BA%E7%94%B5%E8%84%91%E7%9A%84%E5%89%AF%E5%B1%8F.html" title="将pad扩展为电脑的副屏"><img src="/blog/img/skill.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="将pad扩展为电脑的副屏"/></a><div class="content"><a class="title" href="/blog/2021-08-13-%E5%B0%86pad%E6%89%A9%E5%B1%95%E4%B8%BA%E7%94%B5%E8%84%91%E7%9A%84%E5%89%AF%E5%B1%8F.html" title="将pad扩展为电脑的副屏">将pad扩展为电脑的副屏</a><time datetime="2021-08-13T11:44:04.000Z" title="发表于 2021-08-13 19:44:04">2021-08-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021-08-11-Linux%E5%90%AF%E7%94%A8SSH%E6%9C%8D%E5%8A%A1.html" title="Linux启用SSH服务"><img src="/blog/img/shumeipai_cover.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="Linux启用SSH服务"/></a><div class="content"><a class="title" href="/blog/2021-08-11-Linux%E5%90%AF%E7%94%A8SSH%E6%9C%8D%E5%8A%A1.html" title="Linux启用SSH服务">Linux启用SSH服务</a><time datetime="2021-08-11T10:50:04.000Z" title="发表于 2021-08-11 18:50:04">2021-08-11</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By BluesYoung-web</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/blog/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>if (document.getElementsByClassName('mermaid').length) {
  if (window.mermaidJsLoad) mermaid.init()
  else {
    getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(() => {
      window.mermaidJsLoad = true
      mermaid.initialize({
        theme: 'default',
      })
      false && mermaid.init()
    })
  }
}</script></div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script> <script src="/blog/js/xkTool.js"></script> <script src="/blog/js/mySelf.js"></script><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script></div></body></html>